#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>

int main(int argc, char *argv[])
{
	FILE *fp;
	int pid;
	char path[80] = {0};
	int i=0;
	unsigned char buff[2048] = {0};
	unsigned char *p = NULL;

	unsigned char ch = '0';

	if(argc < 2)
	{
		printf("no argument!\n");
		return 0;
	}

	pid = getpid();
	snprintf(path, 80, "/proc/%d/environ", pid);

	printf("%s\n", path);

	if((fp = fopen(path, "r")) ==  NULL )
	{
		perror("fopen");
		return 0;
	}

	while(!feof(fp))
	{
		if((ch = fgetc(fp)) != '\0')
		{
			buff[i]=ch;
			i++;
			continue;
		}
		
		printf("hello world!\n");
		buff[i] = '\0';

		if((p=strstr(buff, argv[1])) != NULL)
		{
			printf("%s\n", p+strlen(argv[1]+1));
			return 0;
		}
		memset(buff, '\0', 1024);
	}

	fclose(fp);
	return 0;
}
